#include "../include/head.h"


// 服务端启动需要的信息初始化
int getValidStr(char *input, char *str) {
      char *p;
      char s[] = {' ', '\n'};
      p = strtok(input, s);
      p = strtok(NULL, s);
      p = strtok(NULL, s);
      strcpy(str, p);
      return 0;
}

int getServerConf(char *fileconf, char *ip, char *port, int *pworkernum) {
      FILE *pconf = fopen(fileconf, "r");
      ERROR_CHECK(pconf, NULL, "open conf file failed");
      char buf[128] = {0};
      fgets(buf, sizeof(buf), pconf);
      getValidStr(buf, ip);
      bzero(buf, sizeof(buf));
      fgets(buf, sizeof(buf), pconf);
      getValidStr(buf, port);
      bzero(buf, sizeof(buf));
      fgets(buf, sizeof(buf), pconf);
      char num[10] = {0};
      getValidStr(buf, num);
      *pworkernum = atoi(num);
      fclose(pconf);
      return 0;
}


